package cn.chengpengper.seckill.stock.interfaces.controller;

import cn.chengpengper.seckill.common.code.ErrorCode;
import cn.chengpengper.seckill.common.response.ResponseMessage;
import cn.chengpengper.seckill.common.response.ResponseMessageBuilder;
import cn.chengpengper.seckill.stock.application.model.command.SeckillStockBucketWrapperCommand;
import cn.chengpengper.seckill.stock.application.model.dto.SeckillStockBucketDTO;
import cn.chengpengper.seckill.stock.application.service.SeckillStockBucketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chengpeng.hu
 */
@RestController
@RequestMapping(value = "/stock/bucket")
public class SeckillStockBucketController {

    @Autowired
    private SeckillStockBucketService seckillStockBucketService;

    /**
     * 库存分桶
     */
    @PostMapping("/v1/arrangeStockBuckets")
    public ResponseMessage<String> arrangeStockBuckets(@RequestAttribute Long userId, @RequestBody SeckillStockBucketWrapperCommand seckillStockCommand) {
        seckillStockBucketService.arrangeStockBuckets(userId, seckillStockCommand);
        return ResponseMessageBuilder.build(ErrorCode.SUCCESS.getCode());
    }

    /**
     * 获取库存分桶数据
     */
    @GetMapping("/v1/getTotalStockBuckets")
    public ResponseMessage<SeckillStockBucketDTO> getTotalStockBuckets(@RequestParam Long goodsId, @RequestParam Long version) {
        return ResponseMessageBuilder.build(ErrorCode.SUCCESS.getCode(), seckillStockBucketService.getTotalStockBuckets(goodsId, version));
    }

}
